package ajjj.kiviq.entities;


import java.io.Serializable;
import java.util.*;
import javax.persistence.*;

/**
 * 
 * Updated 2011-10-04 by jeklund && orjohan
 * -Changed class name from User to UserEnt, as User is reserved
 * -Added property for name
 * 
 * Updated 2011-10-01 by Jonatan
 * - Changed "name" to "id" as name is an SQL-99 reserved keyword
 * - Added named queries
 * 
 * @author orjohan
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "findAllUsers", query = "select u from UserEnt u"),
    @NamedQuery(name = "findAllUsersWithName", query = "select u from UserEnt u where u.name = :name")
})
public class UserEnt implements Serializable {

    private static final long serialVersionUID = 1L;    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column(nullable = false)
    private String name;
    @Column(nullable = false, length = 32)
    private String password;
    @OneToMany(cascade = CascadeType.PERSIST)
    private List<Category> categories = new ArrayList<Category>();

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
    
    public List<Category> getCategories() {
        return categories;
    }

    public void setCategories(List<Category> categories) {
        this.categories = categories;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof UserEnt)) {
            return false;
        }
        UserEnt other = (UserEnt) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return id.toString();
    }
}
